home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 November / CMCD1104.ISO / Software / Freeware / Comunicatii / secclient / setup.exe / {app} / preCharge.exe / 1048 / HTML / FADER.JS next >
Text File  |  2004-08-14  |  5KB  |  159 lines

  1. // This script will no longer overwrite your current onmouseover and
  2. // onmouseout attributes - it will instead skip those links. If you would
  3. // still like to fade them, add findLink(this.id) to your onmouseover
  4. // and clearFade() to your onmouseout, like so -
  5. // <a href="#" onmouseover="findLink(this.id); yourFunction()"
  6. // onmouseout="clearFade(); yourSecondFunction()">
  7. // Make sure to put it BEFORE any "return" statements otherwise
  8. // the fade will not execute.
  9.  
  10. var fadeTo = "ff5555";
  11.  
  12. // Fade in colour increment/decrement by
  13. var fiBy = 6;
  14.  
  15. // Fade out colour increment/decrement by
  16. var foBy = 6;
  17.  
  18. // Speed - milliseconds between each colour change in the fade
  19. // Less than 10ms doesn't really make all that much difference, so
  20. // 10 is the minimum effective value.
  21. var speed = 20;
  22.  
  23. // Class name of links to NOT fade (i.e. ignore)
  24. // var ignoreClass = "somebogusvalue" if you don't want to
  25. // use this feature. Alternatively, add onmouseover="clearFade()"
  26. // to the link you do not wish to fade.
  27. var ignoreClass = "ignore";
  28.  
  29. // No more changes required (unless you know what you are doing)
  30. // Enjoy... and email me and let me know what site(s) you are using it on :)
  31. var opera, ie, dom, x = 0, oc, fader, ocs = new Array();
  32.  
  33. if (navigator.userAgent.indexOf("Opera") != -1) opera = true
  34. else if (document.all && !opera) ie = true
  35. else if (!document.all && document.getElementById) dom = true;
  36.  
  37. function convertRGB(z)
  38.     {
  39.         var newfcS = "", splitter = "";
  40.         splitter = z.split(",");
  41.         splitter[0] = parseInt(splitter[0].substring(4, splitter[0].length));
  42.         splitter[1] = parseInt(splitter[1]);
  43.         splitter[2] = parseInt(splitter[2].substring(0, splitter[2].length-1));
  44.         for (var q = 0; q < 3; q++)
  45.             {
  46.                 splitter[q] = splitter[q].toString(16);
  47.                 if (splitter[q].length == 1) splitter[q] = "0" + splitter[q];
  48.                 newfcS += splitter[q];
  49.             }
  50.         return newfcS;
  51.     }
  52.  
  53. function currentColour(index)
  54.     {
  55.         var temp, cc;
  56.         if (opera) cc = document.links[index].style.color
  57.         else if (ie) cc = document.links[index].currentStyle.color
  58.         else if (dom) cc = document.defaultView.getComputedStyle(document.links[index], '').getPropertyValue("color");
  59.         if (cc.length == 4 && cc.substring(0, 1) == "#")
  60.             {
  61.                 temp = "";
  62.                 for (var a = 0; a < 3; a++)
  63.                     temp += cc.substring(a+1, a+2) + cc.substring(a+1, a+2);
  64.                 cc = temp;
  65.             }
  66.         else if (cc.indexOf("rgb") != -1) cc = convertRGB(cc)
  67.         else if (cc.length == 7) cc = cc.substring(1, 7)
  68.         else cc = fadeTo;
  69.         return cc;
  70.     }
  71.  
  72.  
  73. function convert2Dec(hex)
  74.     {    
  75.         var rgb = new Array();
  76.         for (var u = 0; u < 3; u++)
  77.             rgb[u] = parseInt(hex.substring(u*2, u*2+2), 16);
  78.         return rgb;
  79.     }
  80.  
  81. function newRGB(f, n, d)
  82.     {
  83.         var change;
  84.         if (d == 1) change = fiBy
  85.         else change = foBy;
  86.         for (var g = 0; g < 3; g++)
  87.             {
  88.                 if (n[g] > f[g] && n[g] - change >= 0) n[g] -= change;
  89.                 if (n[g] < f[g] && n[g] + change <= 255) n[g] += change;
  90.             }
  91.         return n;
  92.     }
  93.  
  94. function fade(index, d)
  95.     {
  96.         var fc, nc, temp = new Array(), finished = false;
  97.         nc = convert2Dec(currentColour(index));
  98.         if (d == 1) fc = convert2Dec(fadeTo)
  99.         else fc = convert2Dec(ocs[x]);
  100.         temp = convert2Dec(currentColour(index));
  101.         nc = newRGB(fc, nc, d);
  102.         if ((nc[0] == temp[0]) && (nc[1] == temp[1]) && (nc[2] == temp[2]))
  103.             finished = true;
  104.         if (!finished) document.links[x].style.color = "rgb(" + nc[0] + "," + nc[1] + "," + nc[2] + ")"
  105.         else clearInterval(fader);
  106.     }
  107.  
  108. function findLink(over)
  109.     {
  110.         if (document.layers) return;
  111.         if (fader)
  112.             {
  113.                 clearInterval(fader);
  114.                 document.links[x].style.color = "#" + ocs[x];
  115.             }
  116.         if (over && !this.id) this.id = over;
  117.         x = 0;
  118.         while (!(this.id == document.links[x].id) && (x < document.links.length))
  119.             x++;
  120.         if (this.id == document.links[x].id)
  121.             {
  122.                 oc = currentColour(x);
  123.                 fader = setInterval("fade(" + x  + ", 1)", speed);
  124.             }
  125.     }
  126.  
  127. function clearFade()
  128.     {
  129.         if (document.layers) return;
  130.         if (fader) clearInterval(fader);
  131.         fader = setInterval("fade(" + x + ", 0)", speed);
  132.     }
  133.  
  134. function init()
  135.     {
  136.         for (var i = 0; i < document.links.length; i++)
  137.             {
  138.                 ocs[i] = currentColour(i);
  139.                 var currentOver = document.links[i].onmouseover;
  140.                 var currentOut = document.links[i].onmouseout;
  141.                 var ignoreIt = document.links[i].className == ignoreClass;
  142.                 if (!ignoreIt) document.links[i].id = "link" + i;
  143.                 if (!currentOver && !currentOut && !ignoreIt)
  144.                     {
  145.                         document.links[i].onmouseover = findLink;
  146.                         document.links[i].onmouseout = clearFade;
  147.                     }
  148.             }        
  149. }
  150.  
  151. function clickIE4(){
  152.     if (event.button==2) {
  153.         return false;
  154.     }
  155. }
  156.  
  157. if (opera || ie || dom) window.onload = init;
  158. document.onmousedown=clickIE4;
  159. document.oncontextmenu=new Function("return false");